home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / GNU / emacs.inst / emacs19.idb / usr / gnu / info / elisp-22.z / elisp-22
Encoding:
GNU Info File  |  1994-08-02  |  50.3 KB  |  1,250 lines

  1. This is Info file elisp, produced by Makeinfo-1.55 from the input file
  2. elisp.texi.
  3.  
  4.    This version is newer than the second printed edition of the GNU
  5. Emacs Lisp Reference Manual.  It corresponds to Emacs Version 19.19.
  6.  
  7.    Published by the Free Software Foundation 675 Massachusetts Avenue
  8. Cambridge, MA 02139 USA
  9.  
  10.    Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
  11.  
  12.    Permission is granted to make and distribute verbatim copies of this
  13. manual provided the copyright notice and this permission notice are
  14. preserved on all copies.
  15.  
  16.    Permission is granted to copy and distribute modified versions of
  17. this manual under the conditions for verbatim copying, provided that
  18. the entire resulting derived work is distributed under the terms of a
  19. permission notice identical to this one.
  20.  
  21.    Permission is granted to copy and distribute translations of this
  22. manual into another language, under the above conditions for modified
  23. versions, except that this permission notice may be stated in a
  24. translation approved by the Foundation.
  25.  
  26.    Permission is granted to copy and distribute modified versions of
  27. this manual under the conditions for verbatim copying, provided also
  28. that the section entitled "GNU Emacs General Public License" is included
  29. exactly as in the original, and provided that the entire resulting
  30. derived work is distributed under the terms of a permission notice
  31. identical to this one.
  32.  
  33.    Permission is granted to copy and distribute translations of this
  34. manual into another language, under the above conditions for modified
  35. versions, except that the section entitled "GNU Emacs General Public
  36. License" may be included in a translation approved by the Free Software
  37. Foundation instead of in the original English.
  38.  
  39. 
  40. File: elisp,  Node: Excursions,  Next: Narrowing,  Prev: Motion,  Up: Positions
  41.  
  42. Excursions
  43. ==========
  44.  
  45.    It is often useful to move point "temporarily" within a localized
  46. portion of the program, or to switch buffers temporarily.  This is
  47. called an "excursion", and it is done with the `save-excursion' special
  48. form.  This construct saves the current buffer and its values of point
  49. and the mark so they can be restored after the completion of the
  50. excursion.
  51.  
  52.    The forms for saving and restoring the configuration of windows are
  53. described elsewhere (see *Note Window Configurations::, and *note Frame
  54. Configurations::.).
  55.  
  56.  - Special Form: save-excursion FORMS...
  57.      The `save-excursion' special form saves the identity of the current
  58.      buffer and the values of point and the mark in it, evaluates FORMS,
  59.      and finally restores the buffer and its saved values of point and
  60.      the mark.  All three saved values are restored even in case of an
  61.      abnormal exit via throw or error (*note Nonlocal Exits::.).
  62.  
  63.      The `save-excursion' special form is the standard way to switch
  64.      buffers or move point within one part of a program and avoid
  65.      affecting the rest of the program.  It is used more than 500 times
  66.      in the Lisp sources of Emacs.
  67.  
  68.      The values of point and the mark for other buffers are not saved by
  69.      `save-excursion', so any changes made to point and the mark in the
  70.      other buffers will remain in effect after `save-excursion' exits.
  71.  
  72.      Likewise, `save-excursion' does not restore window-buffer
  73.      correspondences altered by functions such as `switch-to-buffer'.
  74.      One way to restore these correspondences, and the selected window,
  75.      is to use `save-window-excursion' inside `save-excursion' (*note
  76.      Window Configurations::.).
  77.  
  78.      The value returned by `save-excursion' is the result of the last of
  79.      FORMS, or `nil' if no FORMS are given.
  80.  
  81.           (save-excursion
  82.             FORMS)
  83.           ==
  84.           (let ((old-buf (current-buffer))
  85.                 (old-pnt (point-marker))
  86.                 (old-mark (copy-marker (mark-marker))))
  87.             (unwind-protect
  88.                 (progn FORMS)
  89.               (set-buffer old-buf)
  90.               (goto-char old-pnt)
  91.               (set-marker (mark-marker) old-mark)))
  92.  
  93. 
  94. File: elisp,  Node: Narrowing,  Prev: Excursions,  Up: Positions
  95.  
  96. Narrowing
  97. =========
  98.  
  99.    "Narrowing" means limiting the text addressable by Emacs editing
  100. commands to a limited range of characters in a buffer.  The text that
  101. remains addressable is called the "accessible portion" of the buffer.
  102.  
  103.    Narrowing is specified with two buffer positions which become the
  104. beginning and end of the accessible portion.  For most editing commands
  105. these positions replace the values of the beginning and end of the
  106. buffer.  While narrowing is in effect, no text outside the accessible
  107. portion is displayed, and point cannot move outside the accessible
  108. portion.
  109.  
  110.    Values such as positions or line numbers which usually count from the
  111. beginning of the buffer continue to do so, but the functions which use
  112. them will refuse to operate on text that is inaccessible.
  113.  
  114.    The commands for saving buffers are unaffected by narrowing; the
  115. entire buffer is saved regardless of the any narrowing.
  116.  
  117.  - Command: narrow-to-region START END
  118.      This function sets the accessible portion of the current buffer to
  119.      start at START and end at END.  Both arguments should be character
  120.      positions.
  121.  
  122.      In an interactive call, START and END are set to the bounds of the
  123.      current region (point and the mark, with the smallest first).
  124.  
  125.  - Command: narrow-to-page MOVE-COUNT
  126.      This function sets the accessible portion of the current buffer to
  127.      include just the current page.  An optional first argument
  128.      MOVE-COUNT non-`nil' means to move forward or backward by
  129.      MOVE-COUNT pages and then narrow.
  130.  
  131.      In an interactive call, MOVE-COUNT is set to the numeric prefix
  132.      argument.
  133.  
  134.  - Command: widen
  135.      This function cancels any narrowing in the current buffer, so that
  136.      the entire contents are accessible.  This is called "widening".
  137.      It is equivalent to the following expression:
  138.  
  139.           (narrow-to-region 1 (1+ (buffer-size)))
  140.  
  141.  - Special Form: save-restriction BODY...
  142.      This special form saves the current bounds of the accessible
  143.      portion, evaluates the BODY forms, and finally restores the saved
  144.      bounds, thus restoring the same state of narrowing (or absence
  145.      thereof) formerly in effect.  The state of narrowing is restored
  146.      even in the event of an abnormal exit via throw or error (*note
  147.      Nonlocal Exits::.).  Therefore, this construct is a clean way to
  148.      narrow a buffer temporarily.
  149.  
  150.      The value returned by `save-restriction' is that returned by the
  151.      last form in BODY, or `nil' if no body forms were given.
  152.  
  153.      *Caution:* it is easy to make a mistake when using the
  154.      `save-restriction' function.  Read the entire description here
  155.      before you try it.
  156.  
  157.      If BODY changes the current buffer, `save-restriction' still
  158.      restores the restrictions on the original buffer (the buffer they
  159.      came from), but it does not restore the identity of the current
  160.      buffer.
  161.  
  162.      Point and the mark are *not* restored by this special form; use
  163.      `save-excursion' for that.  If you use both `save-restriction' and
  164.      `save-excursion' together, `save-excursion' should come first (on
  165.      the outside).  Otherwise, the old point value would be restored
  166.      with temporary narrowing still in effect.  If the old point value
  167.      were outside the limits of the temporary narrowing, this would
  168.      fail to restore it accurately.
  169.  
  170.      The `save-restriction' special form records the values of the
  171.      beginning and end of the accessible portion as distances from the
  172.      beginning and end of the buffer.  In other words, it records the
  173.      amount of inaccessible text before and after the accessible
  174.      portion.
  175.  
  176.      This technique yields correct results if BODY does further
  177.      narrowing.  However, `save-restriction' can become confused if they
  178.      widen and then make changes outside the area of the saved
  179.      narrowing.  When this is what you want to do, `save-restriction'
  180.      is not the right tool for the job.  Here is what you must use
  181.      instead:
  182.  
  183.           (let ((beg (point-min-marker))
  184.                 (end (point-max-marker)))
  185.             (unwind-protect
  186.                 (progn BODY)
  187.               (save-excursion
  188.                 (set-buffer (marker-buffer beg))
  189.                 (narrow-to-region beg end))))
  190.  
  191.      Here is a simple example of correct use of `save-restriction':
  192.  
  193.           ---------- Buffer: foo ----------
  194.           This is the contents of foo
  195.           This is the contents of foo
  196.           This is the contents of foo-!-
  197.           ---------- Buffer: foo ----------
  198.           
  199.           (save-excursion
  200.             (save-restriction
  201.               (goto-char 1)
  202.               (forward-line 2)
  203.               (narrow-to-region 1 (point))
  204.               (goto-char (point-min))
  205.               (replace-string "foo" "bar")))
  206.           
  207.           ---------- Buffer: foo ----------
  208.           This is the contents of bar
  209.           This is the contents of bar
  210.           This is the contents of foo-!-
  211.           ---------- Buffer: foo ----------
  212.  
  213. 
  214. File: elisp,  Node: Markers,  Next: Text,  Prev: Positions,  Up: Top
  215.  
  216. Markers
  217. *******
  218.  
  219.    A "marker" is a Lisp object used to specify a position in a buffer
  220. relative to the surrounding text.  A marker changes its offset from the
  221. beginning of the buffer automatically whenever text is inserted or
  222. deleted, so that it stays with the two characters on either side of it.
  223.  
  224. * Menu:
  225.  
  226. * Overview of Markers::      The components of a marker, and how it relocates.
  227. * Predicates on Markers::    Testing whether an object is a marker.
  228. * Creating Markers::         Making empty markers or markers at certain places.
  229. * Information from Markers:: Finding the marker's buffer or character position.
  230. * Changing Markers::         Moving the marker to a new buffer or position.
  231. * The Mark::                 How "the mark" is implemented with a marker.
  232. * The Region::               How to access "the region".
  233.  
  234. 
  235. File: elisp,  Node: Overview of Markers,  Next: Predicates on Markers,  Prev: Markers,  Up: Markers
  236.  
  237. Overview of Markers
  238. ===================
  239.  
  240.    A marker specifies a buffer and a position in that buffer.  The
  241. marker can be used to represent a position in the functions that
  242. require one, just as an integer could be used.  *Note Positions::, for
  243. a complete description of positions.
  244.  
  245.    A marker has two attributes: the marker position, and the marker
  246. buffer.  The marker position is an integer which is equivalent (at the
  247. moment) to the marker as a position in that buffer; however, as text is
  248. inserted or deleted in the buffer, the marker is relocated, so that its
  249. integer equivalent changes.  The idea is that a marker positioned
  250. between two characters in a buffer will remain between those two
  251. characters despite any changes made to the contents of the buffer; thus,
  252. a marker's offset from the beginning of a buffer may change often during
  253. the life of the marker.
  254.  
  255.    If the text around a marker is deleted, the marker is repositioned
  256. between the characters immediately before and after the deleted text.
  257. If text is inserted at the position of a marker, the marker remains in
  258. front of the new text unless it is inserted with `insert-before-markers'
  259. (*note Insertion::.).  When text is inserted or deleted somewhere
  260. before the marker position (not next to the marker), the marker moves
  261. back and forth with the two neighboring characters.
  262.  
  263.    When a buffer is modified, all of its markers must be checked so that
  264. they can be relocated if necessary.  This slows processing in a buffer
  265. with a large number of markers.  For this reason, it is a good idea to
  266. make a marker point nowhere if you are sure you don't need it any more.
  267. Unreferenced markers will eventually be garbage collected, but until
  268. then will continue to be updated if they do point somewhere.
  269.  
  270.    Because it is quite common to perform arithmetic operations on a
  271. marker position, most of the arithmetic operations (including `+' and
  272. `-') accept markers as arguments.  In such cases, the current position
  273. of the marker is used.
  274.  
  275.    Here are examples of creating markers, setting markers, and moving
  276. point to markers:
  277.  
  278.      ;; Make a new marker that initially does not point anywhere:
  279.      (setq m1 (make-marker))
  280.           => #<marker in no buffer>
  281.      
  282.      ;; Set `m1' to point between the 100th and 101st characters
  283.      ;;   in the current buffer:
  284.      (set-marker m1 100)
  285.           => #<marker at 100 in markers.texi>
  286.      
  287.      ;; Now insert one character at the beginning of the buffer:
  288.      (goto-char (point-min))
  289.           => 1
  290.      (insert "Q")
  291.           => nil
  292.      
  293.      ;; `m1' is updated appropriately.
  294.      m1
  295.           => #<marker at 101 in markers.texi>
  296.      
  297.      ;; Two markers that point to the same position
  298.      ;;   are not `eq', but they are `equal'.
  299.      (setq m2 (copy-marker m1))
  300.           => #<marker at 101 in markers.texi>
  301.      (eq m1 m2)
  302.           => nil
  303.      (equal m1 m2)
  304.           => t
  305.      
  306.      ;; When you are finished using a marker, make it point nowhere.
  307.      (set-marker m1 nil)
  308.           => #<marker in no buffer>
  309.  
  310. 
  311. File: elisp,  Node: Predicates on Markers,  Next: Creating Markers,  Prev: Overview of Markers,  Up: Markers
  312.  
  313. Predicates on Markers
  314. =====================
  315.  
  316.    You can test an object to see whether it is a marker, or whether it
  317. is either an integer or a marker.  The latter test is useful when you
  318. are using the arithmetic functions that work with both markers and
  319. integers.
  320.  
  321.  - Function: markerp OBJECT
  322.      This function returns `t' if OBJECT is a marker, `nil' otherwise.
  323.      In particular, integers are not markers, even though many
  324.      functions will accept either a marker or an integer.
  325.  
  326.  - Function: integer-or-marker-p OBJECT
  327.      This function returns `t' if OBJECT is an integer or a marker,
  328.      `nil' otherwise.
  329.  
  330.  - Function: number-or-marker-p OBJECT
  331.      This function returns `t' if OBJECT is a number (of any type) or a
  332.      marker, `nil' otherwise.
  333.  
  334. 
  335. File: elisp,  Node: Creating Markers,  Next: Information from Markers,  Prev: Predicates on Markers,  Up: Markers
  336.  
  337. Functions That Create Markers
  338. =============================
  339.  
  340.    When you create a new marker, you can make it point nowhere, or point
  341. to the present position of point, or to the beginning or end of the
  342. accessible portion of the buffer, or to the same place as another given
  343. marker.
  344.  
  345.  - Function: make-marker
  346.      This functions returns a newly allocated marker that does not point
  347.      anywhere.
  348.  
  349.           (make-marker)
  350.                => #<marker in no buffer>
  351.  
  352.  - Function: point-marker
  353.      This function returns a new marker that points to the present
  354.      position of point in the current buffer.  *Note Point::.  For an
  355.      example, see `copy-marker', below.
  356.  
  357.  - Function: point-min-marker
  358.      This function returns a new marker that points to the beginning of
  359.      the accessible portion of the buffer.  This will be the beginning
  360.      of the buffer unless narrowing is in effect.  *Note Narrowing::.
  361.  
  362.  - Function: point-max-marker
  363.      This function returns a new marker that points to the end of the
  364.      accessible portion of the buffer.  This will be the end of the
  365.      buffer unless narrowing is in effect.  *Note Narrowing::.
  366.  
  367.      Here are examples of this function and `point-min-marker', shown in
  368.      a buffer containing a version of the source file for the text of
  369.      this chapter.
  370.  
  371.           (point-min-marker)
  372.                => #<marker at 1 in markers.texi>
  373.           (point-max-marker)
  374.                => #<marker at 15573 in markers.texi>
  375.           
  376.           (narrow-to-region 100 200)
  377.                => nil
  378.           (point-min-marker)
  379.                => #<marker at 100 in markers.texi>
  380.           (point-max-marker)
  381.                => #<marker at 200 in markers.texi>
  382.  
  383.  - Function: copy-marker MARKER-OR-INTEGER
  384.      If passed a marker as its argument, `copy-marker' returns a new
  385.      marker that points to the same place and the same buffer as does
  386.      MARKER-OR-INTEGER.  If passed an integer as its argument,
  387.      `copy-marker' returns a new marker that points to position
  388.      MARKER-OR-INTEGER in the current buffer.
  389.  
  390.      If passed an argument that is an integer whose value is less than
  391.      1, `copy-marker' returns a new marker that points to the beginning
  392.      of the current buffer.  If passed an argument that is an integer
  393.      whose value is greater than the length of the buffer, then
  394.      `copy-marker' returns a new marker that points to the end of the
  395.      buffer.
  396.  
  397.      An error is signaled if MARKER is neither a marker nor an integer.
  398.  
  399.           (setq p (point-marker))
  400.                => #<marker at 2139 in markers.texi>
  401.           
  402.           (setq q (copy-marker p))
  403.                => #<marker at 2139 in markers.texi>
  404.           
  405.           (eq p q)
  406.                => nil
  407.           
  408.           (equal p q)
  409.                => t
  410.           
  411.           (copy-marker 0)
  412.                => #<marker at 1 in markers.texi>
  413.           
  414.           (copy-marker 20000)
  415.                => #<marker at 7572 in markers.texi>
  416.  
  417. 
  418. File: elisp,  Node: Information from Markers,  Next: Changing Markers,  Prev: Creating Markers,  Up: Markers
  419.  
  420. Information from Markers
  421. ========================
  422.  
  423.    This section describes the functions for accessing the components of
  424. a marker object.
  425.  
  426.  - Function: marker-position MARKER
  427.      This function returns the position that MARKER points to, or `nil'
  428.      if it points nowhere.
  429.  
  430.  - Function: marker-buffer MARKER
  431.      This function returns the buffer that MARKER points into, or `nil'
  432.      if it points nowhere.
  433.  
  434.           (setq m (make-marker))
  435.                => #<marker in no buffer>
  436.           (marker-position m)
  437.                => nil
  438.           (marker-buffer m)
  439.                => nil
  440.           
  441.           (set-marker m 3770 (current-buffer))
  442.                => #<marker at 3770 in markers.texi>
  443.           (marker-buffer m)
  444.                => #<buffer markers.texi>
  445.           (marker-position m)
  446.                => 3770
  447.  
  448.    Two distinct markers will be found `equal' (even though not `eq') to
  449. each other if they have the same position and buffer, or if they both
  450. point nowhere.
  451.  
  452. 
  453. File: elisp,  Node: Changing Markers,  Next: The Mark,  Prev: Information from Markers,  Up: Markers
  454.  
  455. Changing Markers
  456. ================
  457.  
  458.    This section describes how to change the position of an existing
  459. marker.  When you do this, be sure you know whether the marker is used
  460. outside of your program, and, if so, what effects will result from
  461. moving it--otherwise, confusing things may happen in other parts of
  462. Emacs.
  463.  
  464.  - Function: set-marker MARKER POSITION &optional BUFFER
  465.      This function moves MARKER to POSITION in BUFFER.  If BUFFER is
  466.      not provided, it defaults to the current buffer.
  467.  
  468.      If POSITION is less than 1, `set-marker' moves marker to the
  469.      beginning of the buffer.  If the value of POSITION is greater than
  470.      the size of the buffer, `set-marker' moves marker to the end of
  471.      the buffer.  If POSITION is `nil' or a marker that points nowhere,
  472.      then MARKER is set to point nowhere.
  473.  
  474.      The value returned is MARKER.
  475.  
  476.           (setq m (point-marker))
  477.                => #<marker at 4714 in markers.texi>
  478.           (set-marker m 55)
  479.                => #<marker at 55 in markers.texi>
  480.           (setq b (get-buffer "foo"))
  481.                => #<buffer foo>
  482.           (set-marker m 0 b)
  483.                => #<marker at 1 in foo>
  484.  
  485.  - Function: move-marker MARKER POSITION &optional BUFFER
  486.      This is another name for `set-marker'.
  487.  
  488. 
  489. File: elisp,  Node: The Mark,  Next: The Region,  Prev: Changing Markers,  Up: Markers
  490.  
  491. The Mark
  492. ========
  493.  
  494.    A special marker in each buffer is designated "the mark".  It
  495. records a position for the user for the sake of commands such as `C-w'
  496. and `C-x TAB'.  Lisp programs should set the mark only to values that
  497. have a potential use to the user, and never for their own internal
  498. purposes.  For example, the `replace-regexp' command sets the mark to
  499. the value of point before doing any replacements, because this enables
  500. the user to move back there conveniently after the replace is finished.
  501.  
  502.    Many commands are designed so that when called interactively they
  503. operate on the text between point and the mark.  If you are writing such
  504. a command, don't examine the mark directly; instead, use `interactive'
  505. with the `r' specification.  This will provide the values of point and
  506. the mark as arguments to the command in an interactive call, but will
  507. permit other Lisp programs to specify arguments explicitly.  *Note
  508. Interactive Codes::.
  509.  
  510.    Each buffer has its own value of the mark that is independent of the
  511. value of the mark in other buffers.  When a buffer is created, the mark
  512. exists but does not point anywhere.  We consider this state as "the
  513. absence of a mark in that buffer".
  514.  
  515.    Once the mark "exists" in a buffer, it normally never ceases to
  516. exist.  However, it may become "inactive", if Transient Mark mode is
  517. enabled.  The variable `mark-active', which is always local in all
  518. buffers, indicates whether the mark is active: non-`nil' means yes.  A
  519. command can request deactivation of the mark upon return to the editor
  520. command loop by setting `deactivate-mark' to a non-`nil' value (but
  521. this deactivation only follows if Transient Mark mode is enabled).
  522.  
  523.    The main motivation for using Transient Mark mode is that this mode
  524. also enables highlighting of the region when the mark is active.  *Note
  525. Display::.
  526.  
  527.    In addition to the mark, each buffer has a "mark ring" which is a
  528. list of markers that are the previous values of the mark.  When editing
  529. commands change the mark, they should normally save the old value of the
  530. mark on the mark ring.  The mark ring may contain no more than the
  531. maximum number of entries specified by the variable `mark-ring-max';
  532. excess entries are discarded on a first-in-first-out basis.
  533.  
  534.  - Function: mark &optional FORCE
  535.      This function returns the position of the current buffer's mark as
  536.      an integer.
  537.  
  538.      Normally, if the mark is inactive `mark' signals an error.
  539.      However, if FORCE is non-`nil', then it returns the mark position
  540.      anyway--or `nil', if the mark is not yet set for this buffer.
  541.  
  542.  - Function: mark-marker
  543.      This function returns the current buffer's mark.  This is the very
  544.      marker which records the mark location inside Emacs, not a copy.
  545.      Therefore, changing this marker's position will directly affect
  546.      the position of the mark.  Don't do it unless that is the effect
  547.      you want.
  548.  
  549.           (setq m (mark-marker))
  550.                => #<marker at 3420 in markers.texi>
  551.           (set-marker m 100)
  552.                => #<marker at 100 in markers.texi>
  553.           (mark-marker)
  554.                => #<marker at 100 in markers.texi>
  555.  
  556.      Like any marker, this marker can be set to point at any buffer you
  557.      like.  We don't recommend that you make it point at any buffer
  558.      other than the one of which it is the mark.  If you do, it will
  559.      yield perfectly consistent, if rather odd, results.
  560.  
  561.  - Function: set-mark POSITION
  562.      This function sets the mark to POSITION, and activates the mark.
  563.      The old value of the mark is *not* pushed onto the mark ring.
  564.  
  565.      *Please note:* use this function only if you want the user to see
  566.      that the mark has moved, and you want the previous mark position to
  567.      be lost.  Normally, when a new mark is set, the old one should go
  568.      on the `mark-ring'.  For this reason, most applications should use
  569.      `push-mark' and `pop-mark', not `set-mark'.
  570.  
  571.      Novice Emacs Lisp programmers often try to use the mark for the
  572.      wrong purposes.  The mark saves a location for the user's
  573.      convenience.  An editing command should not alter the mark unless
  574.      altering the mark is part of the user-level functionality of the
  575.      command.  (And, in that case, this effect should be documented.)
  576.      To remember a location for internal use in the Lisp program, store
  577.      it in a Lisp variable.  For example:
  578.  
  579.           (let ((beg (point)))
  580.             (forward-line 1)
  581.             (delete-region beg (point))).
  582.  
  583.  - Variable: mark-ring
  584.      The value of this buffer-local variable is the list of saved former
  585.      marks of the current buffer, most recent first.
  586.  
  587.           mark-ring
  588.           => (#<marker at 11050 in markers.texi>
  589.               #<marker at 10832 in markers.texi>
  590.               ...)
  591.  
  592.  - User Option: mark-ring-max
  593.      The value of this variable is the maximum size of `mark-ring'.  If
  594.      more marks than this are pushed onto the `mark-ring', it discards
  595.      marks on a first-in, first-out basis.
  596.  
  597.  - Function: push-mark &optional POSITION NOMSG ACTIVATE
  598.      This function sets the current buffer's mark to POSITION, and
  599.      pushes a copy of the previous mark onto `mark-ring'.  If POSITION
  600.      is `nil', then the value of point is used.  `push-mark' returns
  601.      `nil'.
  602.  
  603.      The function `push-mark' normally *does not* activate the mark.
  604.      To do that, specify `t' for the argument ACTIVATE.
  605.  
  606.      A `Mark set' message is displayed unless NOMSG is non-`nil'.
  607.  
  608.  - Function: pop-mark
  609.      This function pops off the top element of `mark-ring' and makes
  610.      that mark become the buffer's actual mark.  This does not change
  611.      the buffer's point, and does nothing if `mark-ring' is empty.  It
  612.      deactivates the mark.
  613.  
  614.      The return value is not useful.
  615.  
  616.  - User Option: transient-mark-mode
  617.      This variable enables Transient Mark mode, in which every
  618.      buffer-modifying primitive sets `deactivate-mark'.  The consequence
  619.      of this is that commands that modify the buffer normally cause the
  620.      mark to become inactive.
  621.  
  622.  - Variable: deactivate-mark
  623.      If an editor command sets this variable non-`nil', then the editor
  624.      command loop deactivates the mark after the command returns.
  625.  
  626.  - Variable: mark-active
  627.      The mark is active when this variable is non-`nil'.  This variable
  628.      is always local in each buffer.
  629.  
  630.  - Variable: activate-mark-hook
  631.  - Variable: deactivate-mark-hook
  632.      These normal hooks are run, respectively, when the mark becomes
  633.      active and when it becomes inactive.  The hook
  634.      `activate-mark-hook' is also run at the end of a command if the
  635.      mark is active and the region may have changed.
  636.  
  637. 
  638. File: elisp,  Node: The Region,  Prev: The Mark,  Up: Markers
  639.  
  640. The Region
  641. ==========
  642.  
  643.    The text between point and the mark is known as "the region".
  644. Various functions operate on text delimited by point and the mark, but
  645. only those functions specifically related to the region itself are
  646. described here.
  647.  
  648.  - Function: region-beginning
  649.      This function returns the position of the beginning of the region
  650.      (as an integer).  This is the position of either point or the mark,
  651.      whichever is smaller.
  652.  
  653.      If the mark does not point anywhere, an error is signaled.
  654.  
  655.  - Function: region-end
  656.      This function returns the position of the end of the region (as an
  657.      integer).  This is the position of either point or the mark,
  658.      whichever is larger.
  659.  
  660.      If the mark does not point anywhere, an error is signaled.
  661.  
  662.    Few programs need to use the `region-beginning' and `region-end'
  663. functions.  A command designed to operate on a region should instead
  664. use `interactive' with the `r' specification, so that the same function
  665. can be called with explicit bounds arguments from programs.  (*Note
  666. Interactive Codes::.)
  667.  
  668. 
  669. File: elisp,  Node: Text,  Next: Searching and Matching,  Prev: Markers,  Up: Top
  670.  
  671. Text
  672. ****
  673.  
  674.    This chapter describes the functions that deal with the text in a
  675. buffer.  Most examine, insert or delete text in the current buffer,
  676. often in the vicinity of point.  Many are interactive.  All the
  677. functions that change the text provide for undoing the changes (*note
  678. Undo::.).
  679.  
  680.    Many text-related functions operate on a region of text defined by
  681. two buffer positions passed in arguments named START and END.  These
  682. arguments should be either markers (*note Markers::.) or or numeric
  683. character positions (*note Positions::.).  The order of these arguments
  684. does not matter; it is all right for START to be the end of the region
  685. and END the beginning.  For example, `(delete-region 1 10)' and
  686. `(delete-region 10 1)' perform identically.  An `args-out-of-range'
  687. error is signaled if either START or END is outside the accessible
  688. portion of the buffer.  In an interactive call, point and the mark are
  689. used for these arguments.
  690.  
  691.    Throughout this chapter, "text" refers to the characters in the
  692. buffer.
  693.  
  694. * Menu:
  695.  
  696. * Near Point::       Examining text in the vicinity of point.
  697. * Buffer Contents::  Examining text in a general fashion.
  698. * Comparing Text::   Comparing substrings of buffers.
  699. * Insertion::        Adding new text to a buffer.
  700. * Commands for Insertion::  User-level commands to insert text.
  701. * Deletion::         Removing text from a buffer.
  702. * User-Level Deletion::     User-level commands to delete text.
  703. * The Kill Ring::    Where removed text sometimes is saved for later use.
  704. * Undo::             Undoing changes to the text of a buffer.
  705. * Maintaining Undo:: How to enable and disable undo information.
  706.             How to control how much information is kept.
  707. * Auto Filling::     How auto-fill mode is implemented to break lines.
  708. * Filling::          Functions for explicit filling.
  709. * Sorting::          Functions for sorting parts of the buffer.
  710. * Indentation::      Functions to insert or adjust indentation.
  711. * Columns::          Computing horizontal positions, and using them.
  712. * Case Changes::     Case conversion of parts of the buffer.
  713. * Text Properties::  Assigning Lisp property lists to text characters.
  714. * Substitution::     Replacing a given character wherever it appears.
  715. * Underlining::      Inserting or deleting underlining-by-overstrike.
  716. * Registers::        How registers are implemented.  Accessing the text or
  717.                        position stored in a register.
  718. * Change Hooks::     Supplying functions to be run when text is changed.
  719.  
  720. 
  721. File: elisp,  Node: Near Point,  Next: Buffer Contents,  Up: Text
  722.  
  723. Examining Text Near Point
  724. =========================
  725.  
  726.    Many functions are provided to look at the characters around point.
  727. Several simple functions are described here.  See also `looking-at' in
  728. *Note Regexp Search::.
  729.  
  730.  - Function: char-after POSITION
  731.      This function returns the character in the current buffer at (i.e.,
  732.      immediately after) position POSITION.  If POSITION is out of range
  733.      for this purpose, either before the beginning of the buffer, or at
  734.      or beyond the end, then the value is `nil'.
  735.  
  736.      Remember that point is always between characters, and the terminal
  737.      cursor normally appears over the character following point.
  738.      Therefore, the character returned by `char-after' is the character
  739.      the cursor is over.
  740.  
  741.      In the following example, assume that the first character in the
  742.      buffer is `@':
  743.  
  744.           (char-to-string (char-after 1))
  745.                => "@"
  746.  
  747.  - Function: following-char
  748.      This function returns the character following point in the current
  749.      buffer.  This is similar to `(char-after (point))'.  However, if
  750.      point is at the end of the buffer, then the result of
  751.      `following-char' is 0.
  752.  
  753.      In this example, point is between the `a' and the `c'.
  754.  
  755.           ---------- Buffer: foo ----------
  756.           Gentlemen may cry ``Pea-!-ce! Peace!,''
  757.           but there is no peace.
  758.           ---------- Buffer: foo ----------
  759.           
  760.           (char-to-string (preceding-char))
  761.                => "a"
  762.           (char-to-string (following-char))
  763.                => "c"
  764.  
  765.  - Function: preceding-char
  766.      This function returns the character preceding point in the current
  767.      buffer.  See above, under `following-char', for an example.  If
  768.      point is at the beginning of the buffer, then the result of
  769.      `preceding-char' is 0.
  770.  
  771.  - Function: bobp
  772.      This function returns `t' if point is at the beginning of the
  773.      buffer.  If narrowing is in effect, this means the beginning of the
  774.      accessible portion of the text.  See also `point-min' in *Note
  775.      Point::.
  776.  
  777.  - Function: eobp
  778.      This function returns `t' if point is at the end of the buffer.
  779.      If narrowing is in effect, this means the end of accessible
  780.      portion of the text.  See also `point-max' in *Note Point::.
  781.  
  782.  - Function: bolp
  783.      This function returns `t' if point is at the beginning of a line.
  784.      *Note Text Lines::.
  785.  
  786.  - Function: eolp
  787.      This function returns `t' if point is at the end of a line.  The
  788.      end of the buffer is always considered the end of a line.
  789.  
  790. 
  791. File: elisp,  Node: Buffer Contents,  Next: Comparing Text,  Prev: Near Point,  Up: Text
  792.  
  793. Examining Buffer Contents
  794. =========================
  795.  
  796.    This section describes two functions that allow a Lisp program to
  797. convert any portion of the text in the buffer into a string.
  798.  
  799.  - Function: buffer-substring START END
  800.      This function returns a string containing a copy of the text of the
  801.      region defined by positions START and END in the current buffer.
  802.      If the arguments are not positions in the accessible portion of
  803.      the buffer, Emacs signals an `args-out-of-range' error.
  804.  
  805.      It is not necessary for START to be less than END; the arguments
  806.      can be given in either order.  But most often the smaller argument
  807.      is written first.
  808.  
  809.           ---------- Buffer: foo ----------
  810.           This is the contents of buffer foo
  811.           
  812.           ---------- Buffer: foo ----------
  813.           
  814.           (buffer-substring 1 10)
  815.           => "This is t"
  816.           (buffer-substring (point-max) 10)
  817.           => "he contents of buffer foo
  818.           "
  819.  
  820.  - Function: buffer-string
  821.      This function returns the contents of the accessible portion of the
  822.      current buffer as a string.  This is the portion between
  823.      `(point-min)' and `(point-max)' (*note Narrowing::.).
  824.  
  825.           ---------- Buffer: foo ----------
  826.           This is the contents of buffer foo
  827.           
  828.           ---------- Buffer: foo ----------
  829.           
  830.           (buffer-string)
  831.                => "This is the contents of buffer foo
  832.           "
  833.  
  834. 
  835. File: elisp,  Node: Comparing Text,  Next: Insertion,  Prev: Buffer Contents,  Up: Text
  836.  
  837. Comparing Text
  838. ==============
  839.  
  840.    This function lets you compare portions of the text in a buffer,
  841. without copying them into strings first.
  842.  
  843.  - Function: compare-buffer-substrings BUFFER1 START1 END1 BUFFER2
  844.           START2 END2
  845.      This function lets you compare two substrings of the same buffer
  846.      or two different buffers.  The first three arguments specify one
  847.      substring, giving a buffer and two positions within the buffer.
  848.      The last three arguments specify the other substring in the same
  849.      way.  You can use `nil' for BUFFER1, BUFFER2 or both to stand for
  850.      the current buffer.
  851.  
  852.      The value is negative if the first substring is less, positive if
  853.      the first is greater, and zero if they are equal.  The absolute
  854.      value of the result is one plus the index of the first differing
  855.      characters within the substrings.
  856.  
  857.      This function ignores case when comparing characters if
  858.      `case-fold-search' is non-`nil'.
  859.  
  860.      Suppose the current buffer contains the text `foobarbar
  861.      haha!rara!'; then in this example the two substrings are `rbar '
  862.      and `rara!'.  The value is 2 because the first substring is greater
  863.      at the second character.
  864.  
  865.           (compare-buffer-substring nil 6 11 nil 16 21)
  866.                => 2
  867.  
  868.      This function does not exist in Emacs version 18 and earlier.
  869.  
  870. 
  871. File: elisp,  Node: Insertion,  Next: Commands for Insertion,  Prev: Comparing Text,  Up: Text
  872.  
  873. Insertion
  874. =========
  875.  
  876.    Insertion takes place at point.  Markers pointing at positions after
  877. the insertion point are relocated with the surrounding text (*note
  878. Markers::.).  When a marker points at the place of insertion, it is
  879. normally not relocated, so that it points to the beginning of the
  880. inserted text; however, when `insert-before-markers' is used, all such
  881. markers are relocated to point after the inserted text.
  882.  
  883.    Point may end up either before or after inserted text, depending on
  884. the function used.  If point is left after the inserted text, we speak
  885. of insertion "before point".
  886.  
  887.    Each of these functions signals an error if the current buffer is
  888. read-only.
  889.  
  890.  - Function: insert &rest ARGS
  891.      This function inserts the strings and/or characters ARGS into the
  892.      current buffer, at point, moving point forward.  An error is
  893.      signaled unless all ARGS are either strings or characters.  The
  894.      value is `nil'.
  895.  
  896.  - Function: insert-before-markers &rest ARGS
  897.      This function inserts the strings and/or characters ARGS into the
  898.      current buffer, at point, moving point forward.  An error is
  899.      signaled unless all ARGS are either strings or characters.  The
  900.      value is `nil'.
  901.  
  902.      This function is unlike the other insertion functions in that a
  903.      marker whose position initially equals point is relocated to come
  904.      after the newly inserted text.
  905.  
  906.  - Function: insert-char CHARACTER COUNT
  907.      This function inserts COUNT instances of CHARACTER into the
  908.      current buffer before point.  COUNT must be a number, and
  909.      CHARACTER must be a character.  The value is `nil'.
  910.  
  911.  - Function: insert-buffer-substring FROM-BUFFER-OR-NAME &optional
  912.           START END
  913.      This function inserts a substring of the contents of buffer
  914.      FROM-BUFFER-OR-NAME (which must already exist) into the current
  915.      buffer before point.  The text inserted consists of the characters
  916.      in the region defined by START and END (These arguments default to
  917.      the beginning and end of the accessible portion of that buffer).
  918.      The function returns `nil'.
  919.  
  920.      In this example, the form is executed with buffer `bar' as the
  921.      current buffer.  We assume that buffer `bar' is initially empty.
  922.  
  923.           ---------- Buffer: foo ----------
  924.           We hold these truths to be self-evident, that all
  925.           ---------- Buffer: foo ----------
  926.           
  927.           (insert-buffer-substring "foo" 1 20)
  928.                => nil
  929.           
  930.           ---------- Buffer: bar ----------
  931.           We hold these truth
  932.           ---------- Buffer: bar ----------
  933.  
  934. 
  935. File: elisp,  Node: Commands for Insertion,  Next: Deletion,  Prev: Insertion,  Up: Text
  936.  
  937. User-Level Insertion Commands
  938. =============================
  939.  
  940.    This section describes higher-level commands for inserting text,
  941. commands intended primarily for the user but useful also in Lisp
  942. programs.
  943.  
  944.  - Command: insert-buffer FROM-BUFFER-OR-NAME
  945.      This function inserts the entire contents of FROM-BUFFER-OR-NAME
  946.      (which must exist) into the current buffer after point.  It leaves
  947.      the mark after the inserted text.  The value is `nil'.
  948.  
  949.  - Command: self-insert-command COUNT
  950.      This function inserts the last character typed COUNT times and
  951.      returns `nil'.  Most printing characters are bound to this
  952.      command.  In routine use, `self-insert-command' is the most
  953.      frequently called function in Emacs, but programs rarely use it
  954.      except to install it on a keymap.
  955.  
  956.      In an interactive call, COUNT is the numeric prefix argument.
  957.  
  958.      This function calls `auto-fill-function' if the current column
  959.      number is greater than the value of `fill-column' and the character
  960.      inserted is a space (*note Auto Filling::.).
  961.  
  962.      This function performs abbrev expansion if Abbrev mode is enabled
  963.      and the inserted character does not have word-constituent syntax.
  964.      (*Note Abbrevs::, and *Note Syntax Class Table::.)
  965.  
  966.      This function is also responsible for calling
  967.      `blink-paren-function' when the inserted character has close
  968.      parenthesis syntax (*note Blinking::.).
  969.  
  970.  - Command: newline &optional NUMBER-OF-NEWLINES
  971.      This function inserts newlines into the current buffer before
  972.      point.  If NUMBER-OF-NEWLINES is supplied, that many newline
  973.      characters are inserted.
  974.  
  975.      In Auto Fill mode, `newline' can break the preceding line if
  976.      NUMBER-OF-NEWLINES is not supplied.  When this happens, it
  977.      actually inserts two newlines at different places: one at point,
  978.      and another earlier in the line.  `newline' does not auto-fill if
  979.      NUMBER-OF-NEWLINES is non-`nil'.
  980.  
  981.      The value returned is `nil'.  In an interactive call, COUNT is the
  982.      numeric prefix argument.
  983.  
  984.  - Command: split-line
  985.      This function splits the current line, moving the portion of the
  986.      line after point down vertically, so that it is on the next line
  987.      directly below where it was before.  Whitespace is inserted as
  988.      needed at the beginning of the lower line, using the `indent-to'
  989.      function.  `split-line' returns the position of point.
  990.  
  991.      Programs hardly ever use this function.
  992.  
  993.  - Variable: overwrite-mode
  994.      This variable controls whether overwrite mode is in effect: a
  995.      non-`nil' value enables the mode.  It is automatically made
  996.      buffer-local when set in any fashion.
  997.  
  998. 
  999. File: elisp,  Node: Deletion,  Next: User-Level Deletion,  Prev: Commands for Insertion,  Up: Text
  1000.  
  1001. Deletion of Text
  1002. ================
  1003.  
  1004.    All of the deletion functions operate on the current buffer, and all
  1005. return a value of `nil'.  In addition to these functions, you can also
  1006. delete text using the "kill" functions that save it in the kill ring;
  1007. some of these functions save text in the kill ring in some cases but
  1008. not in the usual case.  *Note The Kill Ring::.
  1009.  
  1010.  - Function: erase-buffer
  1011.      This function deletes the entire text of the current buffer,
  1012.      leaving it empty.  If the buffer is read-only, it signals a
  1013.      `buffer-read-only' error.  Otherwise, it deletes the text without
  1014.      asking for any confirmation.  The value is always `nil'.
  1015.  
  1016.      Normally, deleting a large amount of text from a buffer inhibits
  1017.      further auto-saving of that buffer "because it has shrunk".
  1018.      However, `erase-buffer' does not do this, the idea being that the
  1019.      future text is not really related to the former text, and its size
  1020.      should not be compared with that of the former text.
  1021.  
  1022.  - Command: delete-region START END
  1023.      This function deletes the text in the current buffer in the region
  1024.      defined by START and END.  The value is `nil'.
  1025.  
  1026.  - Command: delete-char COUNT &optional KILLP
  1027.      This function deletes COUNT characters directly after point, or
  1028.      before point if COUNT is negative.  If KILLP is non-`nil', then it
  1029.      saves the deleted characters in the kill ring.
  1030.  
  1031.      In an interactive call, COUNT is the numeric prefix argument, and
  1032.      KILLP is the unprocessed prefix argument.  Therefore, if a prefix
  1033.      argument is supplied, the text is saved in the kill ring.  If no
  1034.      prefix argument is supplied, then one character is deleted, but
  1035.      not saved in the kill ring.
  1036.  
  1037.      The value returned is always `nil'.
  1038.  
  1039.  - Command: delete-backward-char COUNT &optional KILLP
  1040.      This function deletes COUNT characters directly before point, or
  1041.      after point if COUNT is negative.  If KILLP is non-`nil', then it
  1042.      saves the deleted characters in the kill ring.
  1043.  
  1044.      In an interactive call, COUNT is the numeric prefix argument, and
  1045.      KILLP is the unprocessed prefix argument.  Therefore, if a prefix
  1046.      argument is supplied, the text is saved in the kill ring.  If no
  1047.      prefix argument is supplied, then one character is deleted, but
  1048.      not saved in the kill ring.
  1049.  
  1050.      The value returned is always `nil'.
  1051.  
  1052.  - Command: backward-delete-char-untabify COUNT &optional KILLP
  1053.      This function deletes COUNT characters backward, changing tabs
  1054.      into spaces.  When the next character to be deleted is a tab, it is
  1055.      first replaced with the proper number of spaces to preserve
  1056.      alignment and then one of those spaces is deleted instead of the
  1057.      tab.  If KILLP is non-`nil', then the command saves the deleted
  1058.      characters in the kill ring.
  1059.  
  1060.      If COUNT is negative, then tabs are not changed to spaces, and the
  1061.      characters are deleted by calling `delete-backward-char' with
  1062.      COUNT.
  1063.  
  1064.      In an interactive call, COUNT is the numeric prefix argument, and
  1065.      KILLP is the unprocessed prefix argument.  Therefore, if a prefix
  1066.      argument is supplied, the text is saved in the kill ring.  If no
  1067.      prefix argument is supplied, then one character is deleted, but
  1068.      not saved in the kill ring.
  1069.  
  1070.      The value returned is always `nil'.
  1071.  
  1072. 
  1073. File: elisp,  Node: User-Level Deletion,  Next: The Kill Ring,  Prev: Deletion,  Up: Text
  1074.  
  1075. User-Level Deletion Commands
  1076. ============================
  1077.  
  1078.    This section describes higher-level commands for deleting text,
  1079. commands intended primarily for the user but useful also in Lisp
  1080. programs.
  1081.  
  1082.  - Command: delete-horizontal-space
  1083.      This function deletes all spaces and tabs around point.  It returns
  1084.      `nil'.
  1085.  
  1086.      In the following examples, assume that `delete-horizontal-space' is
  1087.      called four times, once on each line, with point between the
  1088.      second and third characters on the line.
  1089.  
  1090.           ---------- Buffer: foo ----------
  1091.           I -!-thought
  1092.           I -!-     thought
  1093.           We-!- thought
  1094.           Yo-!-u thought
  1095.           ---------- Buffer: foo ----------
  1096.           
  1097.           (delete-horizontal-space)   ; Four times.
  1098.                => nil
  1099.           
  1100.           ---------- Buffer: foo ----------
  1101.           Ithought
  1102.           Ithought
  1103.           Wethought
  1104.           You thought
  1105.           ---------- Buffer: foo ----------
  1106.  
  1107.  - Command: delete-indentation &optional JOIN-FOLLOWING-P
  1108.      This function joins the line point is on to the previous line,
  1109.      deleting any whitespace at the join and in some cases replacing it
  1110.      with one space.  If JOIN-FOLLOWING-P is non-`nil',
  1111.      `delete-indentation' joins this line to the following line
  1112.      instead.  The value is `nil'.
  1113.  
  1114.      If there is a fill prefix, and the second of the lines being joined
  1115.      starts with the prefix, then `delete-indentation' deletes the fill
  1116.      prefix before joining the lines.
  1117.  
  1118.      In the example below, point is located on the line starting
  1119.      `events', and it makes no difference if there are trailing spaces
  1120.      in the preceding line.
  1121.  
  1122.           ---------- Buffer: foo ----------
  1123.           When in the course of human
  1124.           -!-    events, it becomes necessary
  1125.           ---------- Buffer: foo ----------
  1126.           
  1127.           (delete-indentation)
  1128.                => nil
  1129.           
  1130.           ---------- Buffer: foo ----------
  1131.           When in the course of human-!- events, it becomes necessary
  1132.           ---------- Buffer: foo ----------
  1133.  
  1134.      After the lines are joined, the function `fixup-whitespace' is
  1135.      responsible for deciding whether to leave a space at the junction.
  1136.  
  1137.  - Function: fixup-whitespace
  1138.      This function replaces white space between the objects on either
  1139.      side of point with either one space or no space as appropriate.
  1140.      It returns `nil'.
  1141.  
  1142.      The appropriate amount of space is none at the beginning or end of
  1143.      the line.  Otherwise, it is one space except when point is before a
  1144.      character with close parenthesis syntax or after a character with
  1145.      open parenthesis or expression-prefix syntax.  *Note Syntax Class
  1146.      Table::.
  1147.  
  1148.      In the example below, when `fixup-whitespace' is called the first
  1149.      time, point is before the word `spaces' in the first line.  It is
  1150.      located directly after the `(' for the second invocation.
  1151.  
  1152.           ---------- Buffer: foo ----------
  1153.           This has too many     -!-spaces
  1154.           This has too many spaces at the start of (-!-   this list)
  1155.           ---------- Buffer: foo ----------
  1156.  
  1157.           (fixup-whitespace)
  1158.                => nil
  1159.           (fixup-whitespace)
  1160.                => nil
  1161.  
  1162.           ---------- Buffer: foo ----------
  1163.           This has too many spaces
  1164.           This has too many spaces at the start of (this list)
  1165.           ---------- Buffer: foo ----------
  1166.  
  1167.  - Command: just-one-space
  1168.      This command replaces any spaces and tabs around point with a
  1169.      single space.  It returns `nil'.
  1170.  
  1171.  - Command: delete-blank-lines
  1172.      This function deletes blank lines surrounding point.  If point is
  1173.      on a blank line with one or more blank lines before or after it,
  1174.      then all but one of them are deleted.  If point is on an isolated
  1175.      blank line, then it is deleted.  If point is on a nonblank line,
  1176.      the command deletes all blank lines following it.
  1177.  
  1178.      A blank line is defined as a line containing only tabs and spaces.
  1179.  
  1180.      `delete-blank-lines' returns `nil'.
  1181.  
  1182. 
  1183. File: elisp,  Node: The Kill Ring,  Next: Undo,  Prev: User-Level Deletion,  Up: Text
  1184.  
  1185. The Kill Ring
  1186. =============
  1187.  
  1188.    "Kill" functions delete text like the deletion functions, but save
  1189. it so that the user can reinsert it by "yanking".  Most of these
  1190. functions have `kill-' in their name.  By contrast, the functions whose
  1191. names start with `delete-' normally do not save text for yanking
  1192. (though they can still be undone); these are "deletion" functions.
  1193.  
  1194.    Most of the kill commands are primarily for interactive use, and are
  1195. not described here.  What we do describe are the functions provided for
  1196. use in writing such commands.  When deleting text for internal purposes
  1197. within a Lisp function, you should normally use deletion functions, so
  1198. as not to disturb the kill ring contents.  *Note Deletion::.
  1199.  
  1200.    Emacs saves the last several batches of killed text in a list.  We
  1201. call it the "kill ring" because, in yanking, the elements are
  1202. considered to be in a cyclic order.  The list is kept in the variable
  1203. `kill-ring', and can be operated on with the usual functions for lists;
  1204. there are also specialized functions, described in this section, which
  1205. treat it as a ring.
  1206.  
  1207.    Some people think use of the word "kill" in Emacs is unfortunate,
  1208. since it refers to processes which specifically *do not* destroy the
  1209. entities "killed".  This is in sharp contrast to ordinary life, in
  1210. which death is permanent and "killed" entities do not come back to
  1211. life.  Therefore, other metaphors have been proposed.  For example, the
  1212. term "cut ring" makes sense to people who, in pre-computer days, used
  1213. scissors and paste to cut up and rearrange manuscripts.  However, it
  1214. would be difficult to change now.
  1215.  
  1216. * Menu:
  1217.  
  1218. * Kill Ring Concepts::     What text looks like in the kill ring.
  1219. * Kill Functions::         Functions that kill text.
  1220. * Yank Commands::          Commands that access the kill ring.
  1221. * Low Level Kill Ring::       Functions and variables for kill ring access.
  1222. * Internals of Kill Ring:: Variables that hold kill-ring data.
  1223.  
  1224. 
  1225. File: elisp,  Node: Kill Ring Concepts,  Next: Kill Functions,  Up: The Kill Ring
  1226.  
  1227. Kill Ring Concepts
  1228. ------------------
  1229.  
  1230.    The kill ring records killed text as strings in a list.  A short kill
  1231. ring, for example, might look like this:
  1232.  
  1233.      ("some text" "a different piece of text" "yet more text")
  1234.  
  1235.    New entries in the kill ring go at the front of the list.  When the
  1236. list reaches `kill-ring-max' entries in length, adding a new entry
  1237. automatically deletes the last entry.
  1238.  
  1239.    When kill commands are interwoven with other commands, the killed
  1240. portions of text are put into separate entries in the kill ring.  But
  1241. when two or more kill commands are executed in succession, the text they
  1242. kill forms a single entry, because the second and subsequent consecutive
  1243. kill commands append to the entry made by the first one.
  1244.  
  1245.    The user can reinsert or "yank" text from any element in the kill
  1246. ring.  One of the entries in the ring is considered the "front", and
  1247. the simplest yank command yanks that entry.  Other yank commands
  1248. "rotate" the ring by designating other entries as the "front".
  1249.  
  1250.